#ifndef FORMTOWN_H
#define FORMTOWN_H

#include <QWidget>
#include "housingdbms.h"
#include "modelcontainer.h"

#include <QItemSelectionModel>


namespace Ui {
    class FormTown;
}

class FormTown : public QWidget
{
    Q_OBJECT
    HousingDBMS *mp_dbms;
    ApNavTreeModel *mp_apn_model;
   QItemSelectionModel *mp_nav_sel_model;
   QItemSelectionModel *mp_ap_sel_model;
   int  m_current_nav_type;
   QVariant mqv_current_s_db_index;
   QVariant mqv_current_h_db_index;
   QVariant mqv_current_nav_db_index;
   QVariant mqv_current_ap_db_index;
   SLEE_HDB_REC mqh_current_ap_data;

   ApTableModel *mp_apartments_model;

public:
    explicit FormTown(QWidget *parent = 0);
    void set_dbms(HousingDBMS *p_dbms);
    ~FormTown();

    void enable_selection();
    void set_ap_selection(const QVariant &qv_ap_index);
    void hide_sel_btn();

public slots:
    void update_nav_model(bool do_not_load = false);
protected:
    void resizeEvent(QResizeEvent *);
    void showEvent(QShowEvent *);
protected slots:
    void nav_tree_item_selected(const QModelIndex &index);
    void restore_nav_selection();
    void apartment_item_activated(const QModelIndex &index);
    void apartment_item_selected(const QModelIndex &index);
    void restore_ap_selection();
    void nav_tree_edit_request(const QModelIndex &index);
    void add_street();
    void add_house();
    void remove_nav_tree_item();
    void remove_apartment();
    void add_apartment();
    void select_record();
    void splitter_resized();
signals:
    void record_selected(QVariant );
private:
    Ui::FormTown *ui;
};

#endif // FORMTOWN_H
